import { img_prefix_url } from '@/config/site'
// import NewsItem from '../../components/NewsItem'
export default {
    data() {
        return {
            isloading: false,
            loadingNews:false,
            img_prefix_url,
            active: 0,
            // list: [],
            finished: false,
            // 获取的banner图片列表
            imgList: [],
            // 获取分类列表
            cateList: [],
            // 获取新闻列表
            cate_id: '国家事实',
            newsList: [],
            newsTotal: 0,
            // 一次获取多少条新闻
            num: 5,
            // 下拉刷新
            // refreshing: false,
            // 新闻详情
            // newsDetail: {},
        };
    },
    mounted() {
        // this.loading = false;
    },
    created() {
        this.getBannerHandler()
        this.getCatelistHandler()
        this.getNewslistHandler()
    },
    // components: {
    //         NewsItem,
    //     },
    methods: {
        pushList() {

        },
        test(){
            console.log(this.loading);
        },
        typeTabsNum(e){
            console.log(e);
            console.log(e.target.dataset);
        },
        onLoad() {
            // console.log(this.loading);
            // this.loading = true;
        },
        getBannerHandler() {
            this.getBanner()
        },
        changCateId(name, title) {
            console.log(name, title);
            this.cate_id = title;
            this.getNewslist()
        },
        getCatelistHandler() {
            this.getCatelist();
        },
        getNewslistHandler() {
            this.getNewslist();
        },
        goDetail(newsId) {
            // 这里无法或者指定dom的e
            // console.log(e);
            // console.log(e.target.dataset);
            // console.log(newsId);
            // 使用路由别名
            this.$router.push({
                name:"detail",
                query: {
                    newsId: newsId,
                }
            })
            console.log(id);
            this.$router.push('/detail/' + id);
            this.getNewsDetail();
        },
        async getBanner() {
            this.isloading = true;
            const res = await this.$http.get('v1/banner/bypos', {
                params: {
                    id: '6268bce29114094ca0ed2354',
                }
            })
            // const res = await this.$http.get('/banner/list');
            // console.log(res);
            this.isloading = false;
            if (res.data.statusCode === 200) {
                this.imgList = res.data.data.info.banners;
                // console.log(this.loading);
            } else {
                // vant的全局消息通知
                this.$notify({
                    type: 'danger',
                    message: '获取轮播图失败',
                    duration: 1000,
                });
                console.log(res);
                // console.log(res.data.message);
            }
        },

        async getCatelist() {
            const res = await this.$http.get('cate/flist')
            // this.loading = false;
            // console.log(res);
            if (res.data.statusCode === 200) {
                console.log(res.data.data.list);
                this.cateList = res.data.data.list;
            } else {
                // vant的全局消息通知
                this.$notify({
                    type: 'danger',
                    message: '获取分类失败',
                    duration: 1000,
                });
                console.log(res.data.message);
            }
        },

        async getNewslist() {
            this.loadingNews = true;
            const res = await this.$http.get('news/flist', {
                params: {
                    pageSize: 100,
                    // pageSize: this.num,//5
                    cate_id: this.cate_id,
                    currentPage: 1,
                }
            })
            console.log(res);
            this.loadingNews = false;
            if (res.data.statusCode === 200) {
                // 一次性渲染
                this.newsList = res.data.data.list;
            } else {
                // vant的全局消息通知
                this.$notify({
                    type: 'danger',
                    message: '获取分类失败',
                    duration: 1000,
                });
                console.log(res.data.message);
            }
        },
    }
};